﻿
function getParams() {
    var params = {};

    var aliPayCardName = $("input[name='aliPayCardName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(aliPayCardName)) {
        params.aliPayCardName = aliPayCardName;
    }

    var bankName = $("input[name='bankName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(bankName)) {
        params.bankName = bankName;
    }

    var cardNumber = $("input[name='cardNumber']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(cardNumber)) {
        params.cardNumber = cardNumber;
    }

    var cardName = $("input[name='cardName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(cardName)) {
        params.cardName = cardName;
    }

    var enableStatus = $("select[name='enableStatus']").find("option:selected").val();
    if (!FlashPay.Util.isNullOrEmptySpance(enableStatus)) {
        params.enableStatus = enableStatus;
    }

    return params;
}

function doSearch() {
    
    var columns = [[
        { field: 'bankName', title: '银行名称', width: 100, align: 'left' },
        { field: 'cardName', title: '用户名', width: 100, align: 'left' },
        {
            field: 'cardNumberText', title: '银行卡号', width: 125, align: 'left',
            formatter: function (val, item) {
                return FlashPay.Util.SubCardNumber(val);
            }
        },
        {
            field: 'secCardNumber', title: '副卡号', width: 125, align: 'left',
            formatter: function (val, item) {
                return FlashPay.Util.SubCardNumber(val);
            }
        },
        {
            field: 'cardType', title: '类型', width: 100, align: 'center',
            formatter: function (val, item) {
                return FlashPay.Util.GetCardTypeValue(val);
            }
        },
        {
            field: 'usingStatus', title: '使用状态', width: 100, align: 'center',
            formatter: function (val, row) {
                return FlashPay.Util.GetCardStatusValue(val);
            }
        },
        {
            field: 'enableStatus', title: '启用状态', width: 100, align: 'center',
            formatter: function (val, row) {
                return FlashPay.Util.GetCardEnableStatusValue(val);
            }
        },
        { field: 'createName', title: '建立人员', width: 125, align: 'left' },
        { field: 'createDate', title: '建立时间', width: 130, align: 'left' },
        { field: 'aliPayCardName', title: '支付宝姓名', width: 130, align: 'left' },
        { field: 'remark', title: '备注', width: 130, align: 'left' },
        {
            field: 'bcid', title: '操作', width: 200, align: 'center',
            formatter: function (val, item) {

                var result = '';

                if (item.enableStatus == 1 || item.enableStatus == 2) {
                    result = '<a class="btn btn-warning btn-xs" data-confirm="{0} <br>确定要<span class=orange>收回授权</span>该银行卡？" data-href="/Bank/B2BUpdateAuthStatus?id={1}&status=4">收回授权</a >'.format(item.cardName, val);
                } else {
                    result = '<a class="btn btn-warning btn-xs" data-confirm="{0} <br>确定要<span class=orange>给予授权</span>该银行卡？" data-href="/Bank/B2BUpdateAuthStatus?id={1}&status=2">给予授权</a>'.format(item.cardName, val);
                    result += ' <a class="btn btn-danger btn-xs" data-confirm="{0} <br>确定要<span class=red>删除</span>该银行卡？" data-href="/Bank/B2BStockCardDelete?id={1}&status=2">删除</a>'.format(item.cardName, val);
                }
                if (item.enableStatus == 4) {
                    result += ' <button type="button" class="btn btn-default btn-xs" data-href="/view/bankcard/editb2bspare.html?id={0}" data-title="编辑 - {1}" data-width="452" data-height="550" onclick="return dialogOpen(this)"><span class="glyphicon glyphicon-edit"></span> 编辑</button>'.format(val, item.cardName);
                }

                
                return result;
            }
        }
    ]];

    $("#indexB2BSpare").datagrid({
        fit: false,
        loadMsg: '数据加载中，请稍后……',
        method: "get",
        border: true,
        url: "/Bank/GetB2BStockPager",
        queryParams: getParams(),
        pagination: true,
        pageSize: pageSize,
        pageList: [15, 30, 50, 100, 1000],
        height: $(window).height() - 70,
        singleSelect: true,
        //fitColumns: true,
        rownumbers: true,
        showFooter: true,
        columns: columns,
        onLoadSuccess: function (data) {
            pageSize = $('#indexB2BSpare').datagrid('options').pageSize;
        }
    });
}